﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Net.Mail;

public class MailBLL
{
    private static string _fromAddress;
    private static string _fromPassword;
    private static string _smtpHost;
    private static string _displayName;
    private static int _port;

    public MailBLL()
    {
        _fromAddress = "info@ucnlink.dk";
        _fromPassword = "6ypkdxar";
        _smtpHost = "smtp.unoeuro.com";
        _displayName = "UCNLink.dk";
        _port = 25;
    }
    public MailBLL(string addressFrom, string passwordFrom, string hostSmtp, string displayName)
    {
        _fromAddress = addressFrom;
        _fromPassword = passwordFrom;
        _smtpHost = hostSmtp;
        _displayName = displayName;
    }
    public void SendMail(string _recieverMail, string _subjectText, string _bodyText)
    {
        MailMessage mail = new MailMessage();
        mail.From = new MailAddress(_fromAddress, _displayName);
        mail.To.Add(_recieverMail);
        mail.Subject = _subjectText;
        mail.Body = _bodyText;
        SmtpClient clientSmtp = new SmtpClient(_smtpHost, _port);
        clientSmtp.EnableSsl = false;
        clientSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        clientSmtp.UseDefaultCredentials = false;
        clientSmtp.Credentials = new NetworkCredential(_fromAddress, _fromPassword);
        clientSmtp.Send(mail);
    }
    /// <summary>
    /// Insert a number between 1 - 4 for a new port;
    /// </summary>
    /// <param name="x">1 = 25; 2 = 587; 3 = 2525; 4 = 8080</param>
    public void SetPort(int x)
    {
        switch (x)
        {
            case 1: _port = 25; break;
            case 2: _port = 587; break;
            case 3: _port = 2525; break;
            case 4: _port = 8080; break;
        }
    }
}